	OpenLayers.Popup.FramedCloud.prototype.fixedRelativePosition = true;
	OpenLayers.Popup.FramedCloud.prototype.relativePosition = "tr";
	/**
     * Property: positionBlocks
     * {Object} Hash of differen position blocks, keyed by relativePosition
     *     two-character code string (ie "tl", "tr", "bl", "br")
     */
    OpenLayers.Popup.FramedCloud.prototype.positionBlocks = {
        "tl": {
            'offset': new OpenLayers.Pixel(44, 0),
            'padding': new OpenLayers.Bounds(8, 40, 8, 9),
            'blocks': [
                { // top-left
                    size: new OpenLayers.Size('auto', 'auto'),
                    anchor: new OpenLayers.Bounds(0, 51, 22, 0),
                    position: new OpenLayers.Pixel(0, 0)
                },
                { //top-right
                    size: new OpenLayers.Size(22, 'auto'),
                    anchor: new OpenLayers.Bounds(null, 50, 0, 0),
                    position: new OpenLayers.Pixel(-638, 0)
                },
                { //bottom-left
                    size: new OpenLayers.Size('auto', 19),
                    anchor: new OpenLayers.Bounds(0, 32, 22, null),
                    position: new OpenLayers.Pixel(0, -631)
                },
                { //bottom-right
                    size: new OpenLayers.Size(22, 18),
                    anchor: new OpenLayers.Bounds(null, 32, 0, null),
                    position: new OpenLayers.Pixel(-638, -632)
                },
                { // stem
                    size: new OpenLayers.Size(81, 35),
                    anchor: new OpenLayers.Bounds(null, 0, 0, null),
                    position: new OpenLayers.Pixel(0, -688)
                }
            ]
        },
        "tr": {
            'offset': new OpenLayers.Pixel(-42, 15),
            'padding': new OpenLayers.Bounds(8, 40, 8, 9),
            'blocks': [
                { // top-left
                    size: new OpenLayers.Size('auto', 'auto'),
                    anchor: new OpenLayers.Bounds(0, 51, 22, 0),
                    position: new OpenLayers.Pixel(0, 0)
                },
                { //top-right
                    size: new OpenLayers.Size(22, 'auto'),
                    anchor: new OpenLayers.Bounds(null, 50, 0, 0),
                    position: new OpenLayers.Pixel(-638, 0)
                },
                { //bottom-left
                    size: new OpenLayers.Size('auto', 19),
                    anchor: new OpenLayers.Bounds(0, 32, 22, null),
                    position: new OpenLayers.Pixel(0, -631)
                },
                { //bottom-right
                    size: new OpenLayers.Size(22, 19),
                    anchor: new OpenLayers.Bounds(null, 32, 0, null),
                    position: new OpenLayers.Pixel(-638, -631)
                },
                { // stem
                    size: new OpenLayers.Size(81, 35),
                    anchor: new OpenLayers.Bounds(0, 0, null, null),
                    position: new OpenLayers.Pixel(-215, -687)
                }
            ]
        },
        "bl": {
            'offset': new OpenLayers.Pixel(45, 0),
            'padding': new OpenLayers.Bounds(8, 9, 8, 40),
            'blocks': [
                { // top-left
                    size: new OpenLayers.Size('auto', 'auto'),
                    anchor: new OpenLayers.Bounds(0, 21, 22, 32),
                    position: new OpenLayers.Pixel(0, 0)
                },
                { //top-right
                    size: new OpenLayers.Size(22, 'auto'),
                    anchor: new OpenLayers.Bounds(null, 21, 0, 32),
                    position: new OpenLayers.Pixel(-638, 0)
                },
                { //bottom-left
                    size: new OpenLayers.Size('auto', 21),
                    anchor: new OpenLayers.Bounds(0, 0, 22, null),
                    position: new OpenLayers.Pixel(0, -629)
                },
                { //bottom-right
                    size: new OpenLayers.Size(22, 21),
                    anchor: new OpenLayers.Bounds(null, 0, 0, null),
                    position: new OpenLayers.Pixel(-638, -629)
                },
                { // stem
                    size: new OpenLayers.Size(81, 33),
                    anchor: new OpenLayers.Bounds(null, null, 0, 0),
                    position: new OpenLayers.Pixel(-101, -674)
                }
            ]
        },
        "br": {
            'offset': new OpenLayers.Pixel(-44, 0),
            'padding': new OpenLayers.Bounds(8, 9, 8, 40),
            'blocks': [
                { // top-left
                    size: new OpenLayers.Size('auto', 'auto'),
                    anchor: new OpenLayers.Bounds(0, 21, 22, 32),
                    position: new OpenLayers.Pixel(0, 0)
                },
                { //top-right
                    size: new OpenLayers.Size(22, 'auto'),
                    anchor: new OpenLayers.Bounds(null, 21, 0, 32),
                    position: new OpenLayers.Pixel(-638, 0)
                },
                { //bottom-left
                    size: new OpenLayers.Size('auto', 21),
                    anchor: new OpenLayers.Bounds(0, 0, 22, null),
                    position: new OpenLayers.Pixel(0, -629)
                },
                { //bottom-right
                    size: new OpenLayers.Size(22, 21),
                    anchor: new OpenLayers.Bounds(null, 0, 0, null),
                    position: new OpenLayers.Pixel(-638, -629)
                },
                { // stem
                    size: new OpenLayers.Size(81, 33),
                    anchor: new OpenLayers.Bounds(0, null, null, 0),
                    position: new OpenLayers.Pixel(-311, -674)
                }
            ]
        }
    };﻿   
 OpenLayers.Control.Panel.prototype.activateControl = function (control) {
        if (!this.active) { return false; }
        if (control.type == OpenLayers.Control.TYPE_BUTTON) {
            control.trigger();
            this.redraw();
            return;
        }
        if (control.type == OpenLayers.Control.TYPE_TOGGLE) {
            if (control.active) {
                control.deactivate();
            } else {
                control.activate();
            }
            this.redraw();
            return;
        }
        for (var i=0, len=this.controls.length; i<len; i++) {
            if (this.controls[i] != control) {
                if (this.controls[i].type != OpenLayers.Control.TYPE_TOGGLE) {
                    this.controls[i].deactivate();
                }
            }
        }
        control.activate();                       
        if(control.map) {
            for(var i = 0; i < control.map.controls.length; i++){
                var control2 = control.map.controls[i];
                if(control2.controls){                
                    for(var j = 0; j < control2.controls.length;j++){
                        var control1 = control2.controls[j];
                        if(control1 != control)
                            control1.deactivate();
                    }
                }
                else {
                    if(control2 != control)
                         control2.deactivate();
                }
            }
        }                        
    };   
    OpenLayers.Layer.Vector.prototype.removeFeatureById = function(id){
    		for(var i = this.features.length - 1; i >= 0; i--){
    			var fea = this.features[i];
    			if(fea.id == id){    		    					
    				this.removeFeatures(fea);
    			}
    		}
    	};
    	OpenLayers.Marker.prototype.draw = function(px){
    		var imgdiv = this.icon.draw(px);
    		OpenLayers.Util.modifyAlphaImageDiv(imgdiv, 
                                            null, 
                                            null, 
                                            null,null,null,null,'crop');
    		imgdiv.style.overflow='visible';
    		imgdiv.style.width = "550px";
    		imgdiv.innerHTML += this.label;
    		return imgdiv;
    	};    
    OpenLayers.Icon.prototype.moveTo = function (px) {
        //if no px passed in, use stored location
        if (px != null) {
            this.px = px;
        }

        if (this.imageDiv != null) {
            if (this.px == null) {
                this.display(false);
            } else {
                if (this.calculateOffset) {
                    this.offset = this.calculateOffset(this.size);  
                }
                var offsetPx = this.px.offset(this.offset);
                OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, offsetPx,null,null,null,null,'crop');
            }
        }
    },
    /**
     * Method: loadText
     * Start the load of the Text data. Don't do this when we first add the layer,
     * since we may not be visible at any point, and it would therefore be a waste.
     */
    OpenLayers.Layer.Text.prototype.loadText= function() {    	
        if (!this.loaded && this.location) {
            this.clearFeatures();
	        this.clearMarkers();
            if (this.location != null) {
                var onFail = function(e) {
                    this.events.triggerEvent("loadend");
                };
                this.events.triggerEvent("loadstart");
                var env = this.getExtent().transform(this.map.getProjectionObject(),this.map.displayProjection);
                var envstr = env.left + "," + env.bottom + "," + env.right + "," + env.top;
                OpenLayers.Request.GET({
                    url: this.location,
                    success: this.parseData,
                    failure: onFail,
                    scope: this
                });
                this.loaded = true;
            }
        }    
    };    
    function toMarkersText(lon,lat,title, description, icon,label,iconSize){
    	var text = 'lon\tlat\ttitle\tdescription\tlabel\ticon\ticonSize\n';
    	text += lon + '\t' + lat + '\t' + title + '\t' + description + '\t' + label + '\t' + icon + '\t' + iconSize + '\n';
    	return text;
    }
    OpenLayers.Layer.Text.prototype.insertMarkersByParams = function(id,lon,lat,title, description, icon,label,iconSize) {                    	
    		this.insertMarkers(id,toMarkersText(lon,lat,title, description, label,icon,iconSize));
    };
    OpenLayers.Layer.Text.prototype.removeMarkerById = function(id) {
    		for(var i = this.features.length - 1; i >= 0; i--){
    			var fea = this.features[i];
    			if(fea.id == id){
    				this.removeMarker(fea.marker);
    				OpenLayers.Util.removeItem(this.features, fea);
                		fea.destroy();    				
    			}
    		}
    	};
    OpenLayers.Layer.Text.prototype.insertMarkers = function(id,text) {                    	
        var options = {};        
        OpenLayers.Util.extend(options, this.formatOptions);
        
        if (this.map && !this.projection.equals(this.map.getProjectionObject())) {
            options.externalProjection = this.projection;
            options.internalProjection = this.map.getProjectionObject();
        }    
        
        var parser = new OpenLayers.Format.Text(options);
        var features = parser.read(text);
        for (var i=0, len=features.length; i<len; i++) {
            var data = {};
            var feature = features[i];
            var location;
            var iconSize, iconOffset;
            
            location = new OpenLayers.LonLat(feature.geometry.x, 
                                             feature.geometry.y);
            
            if (feature.style.graphicWidth 
                && feature.style.graphicHeight) {
                iconSize = new OpenLayers.Size(
                    feature.style.graphicWidth,
                    feature.style.graphicHeight);
            }        
            
            // FIXME: At the moment, we only use this if we have an 
            // externalGraphic, because icon has no setOffset API Method.
            /**
             * FIXME FIRST!!
             * The Text format does all sorts of parseFloating
             * The result of a parseFloat for a bogus string is NaN.  That
             * means the three possible values here are undefined, NaN, or a
             * number.  The previous check was an identity check for null.  This
             * means it was failing for all undefined or NaN.  A slightly better
             * check is for undefined.  An even better check is to see if the
             * value is a number (see #1441).
             */
            if (feature.style.graphicXOffset !== undefined
                && feature.style.graphicYOffset !== undefined) {
                iconOffset = new OpenLayers.Pixel(
                    feature.style.graphicXOffset, 
                    feature.style.graphicYOffset);
            }
            
            if (feature.style.externalGraphic != null) {
                data.icon = new OpenLayers.Icon(feature.style.externalGraphic, 
                                                iconSize, 
                                                iconOffset);
            } else {
                data.icon = OpenLayers.Marker.defaultIcon();

                //allows for the case where the image url is not 
                // specified but the size is. use a default icon
                // but change the size
                if (iconSize != null) {
                    data.icon.setSize(iconSize);
                }
            }
            
            if ((feature.attributes.title != null) 
                && (feature.attributes.description != null)) {
                data['popupContentHTML'] = 
                    '<h2>'+feature.attributes.title+'</h2>' + 
                    '<p>'+feature.attributes.description+'</p>';
            }
            
            data['overflow'] = feature.attributes.overflow || "auto"; 
            
            var markerFeature = new OpenLayers.Feature(this, location, data);
            markerFeature.id = id;
                        markerFeature.closeBox = true;
            markerFeature.popupClass = AutoSizeFramedCloud;
            this.features.push(markerFeature);
            var marker = markerFeature.createMarker();
            marker.label = feature.attributes.label;
            if ((feature.attributes.title != null) 
                && (feature.attributes.description != null)) {
              marker.events.register('click', markerFeature, this.markerClick);
            }
            this.addMarker(marker);
            return;
        }
        this.events.triggerEvent("loadend");
    };    
    var AutoSizeFramedCloud = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
            'autoSize': true
        });
OpenLayers.Layer.Text.prototype.markerClick = function(evt) {
	        var sameMarkerClicked = (this == this.layer.selectedFeature);
	        this.layer.selectedFeature = (!sameMarkerClicked) ? this : null;
	        for(var i=0, len=this.layer.map.popups.length; i<len; i++) {
	            this.layer.map.removePopup(this.layer.map.popups[i]);
	        };
	        if (!sameMarkerClicked || true) {
	        		var popup1 = this.createPopup(this.closeBox);
	        		popup1.map = this.layer.map;
	            this.layer.map.addPopup(popup1); 
	            popup1.show();
	        }
	        OpenLayers.Event.stop(evt);
	    }	    ;
OpenLayers.Layer.TextCustom = OpenLayers.Class(OpenLayers.Layer.Text, {	
    loadText:function() {    	
            this.clearFeatures();
	        this.clearMarkers();    
        if (!this.loaded && this.location) {
            if (this.location != null) {
                var onFail = function(e) {
                    alert(e.responseText);
                    this.events.triggerEvent("loadend");
                };
                this.events.triggerEvent("loadstart");
                var env = this.getExtent().transform(this.map.getProjectionObject(),this.map.displayProjection);
                var envstr = env.left + "," + env.bottom + "," + env.right + "," + env.top;
                var param1  = this.map.getZoom() >= map.getZoomForResolution(viewPointRes,true) ? "":"&count=" + itemcount;
                OpenLayers.Request.GET({
                    url: this.location + "&env=" + envstr + "&random=" + random + param1,
                    success: this.parseData,
                    failure: onFail,
                    scope: this
                });
                this.loaded = true;
            }
        }    
        }
});	    
OpenLayers.Layer.TileCacheCustom = OpenLayers.Class(OpenLayers.Layer.TileCache, {	
	getURL:function(bounds){	    	    
		var res = this.map.getResolution();
		var bbox = this.maxExtent;
		var size = this.tileSize;
	        var tileX = Math.round((bounds.left - bbox.left) / (res * size.w));
	        var tileY = Math.round((bbox.top - bounds.top) / (res * size.h));
	        var tileZ = this.serverResolutions != null ?	        
	            OpenLayers.Util.indexOf(this.serverResolutions, res) :
	            this.map.getZoom();	        
		var rowID = "00000000" + Math.abs(tileY).toString(16).toLowerCase();
		var colID = "00000000" + Math.abs(tileX).toString(16).toLowerCase();  
		rowID = (tileY >= 0 ? "":"-") + rowID.substr(rowID.length - 8);
		colID = (tileX >= 0 ? "":"-") + colID.substr(colID.length - 8);				
	        var path = "/R" + rowID + "/C" + colID + ".jpg";      	        
        var url1 = this.url[tileZ];      
        return url1 + path;
	},
    /**
     * Method: addTile
     * Create a tile, initialize it, and add it to the layer div. 
     *
     * Parameters: 
     * bounds - {<OpenLayers.Bounds>} 
     * position - {<OpenLayers.Pixel>}
     *
     * Returns:
     * {<OpenLayers.Tile.Image>} The added <OpenLayers.Tile.Image>
     */
    addTile:function(bounds1, position) 
    {
        var url = this.getURL(bounds1);
        return new OpenLayers.Tile.Image(this, position, bounds1, 
                                             url, this.tileSize);
    },
    
    
    initialize: function(name, url, params, options) {
        OpenLayers.Layer.TileCache.prototype.initialize.apply(this, arguments);
    },
    calculateGridLayout: function(bounds, extent, resolution) {
        var tilelon = resolution * this.tileSize.w;
        var tilelat = resolution * this.tileSize.h;
        
        var offsetlon = bounds.left - extent.left;
        var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
        var tilecolremain = offsetlon/tilelon - tilecol;
        var tileoffsetx = -tilecolremain * this.tileSize.w;
        var tileoffsetlon = extent.left + tilecol * tilelon;
        
        var offsetlat = extent.top - bounds.top;  
        var tilerow = Math.floor(offsetlat/tilelat) - this.buffer;
        var tilerowremain = offsetlat/tilelat - tilerow + 1;
        var tileoffsety = -tilerowremain * this.tileSize.h;
        var tileoffsetlat = extent.top - tilerow * tilelat;
        
        //alert(tileoffsetx + "  " + tileoffsety + "\n" + tileoffsetlon + "  " + tileoffsetlat);
        
        return { 
          tilelon: tilelon, tilelat: tilelat,
          tileoffsetlon: tileoffsetlon, tileoffsetlat: tileoffsetlat,
          tileoffsetx: tileoffsetx, tileoffsety: tileoffsety
        };

    },    
    initGriddedTiles:function(bounds){
	var viewSize = this.map.getSize();
        var minRows = Math.ceil(viewSize.h/this.tileSize.h) + 
                      Math.max(1, 2 * this.buffer);
        var minCols = Math.ceil(viewSize.w/this.tileSize.w) +
                      Math.max(1, 2 * this.buffer);
        
        var extent = this.map.getMaxExtent();
        var resolution = this.map.getResolution();   
        var tileLayout = this.calculateGridLayout(bounds, extent, resolution);

        var tileoffsetx = Math.round(tileLayout.tileoffsetx); // heaven help us
        var tileoffsety = Math.round(tileLayout.tileoffsety);

        var tileoffsetlon = tileLayout.tileoffsetlon;
        var tileoffsetlat = tileLayout.tileoffsetlat;
        
        var tilelon = tileLayout.tilelon;
        var tilelat = tileLayout.tilelat;

        this.origin = new OpenLayers.Pixel(tileoffsetx, tileoffsety);

        var startX = tileoffsetx; 
        var startLon = tileoffsetlon;

        var rowidx = 0;
        
        var layerContainerDivLeft = parseInt(this.map.layerContainerDiv.style.left);
        var layerContainerDivTop = parseInt(this.map.layerContainerDiv.style.top);
        
    
        do {
            var row = this.grid[rowidx++];
            if (!row) {
                row = [];
                this.grid.push(row);
            }

            tileoffsetlon = startLon;
            tileoffsetx = startX;
            var colidx = 0;
 
            do {
                var tileBounds = 
                    new OpenLayers.Bounds(tileoffsetlon, 
                                          tileoffsetlat, 
                                          tileoffsetlon + tilelon,
                                          tileoffsetlat + tilelat);

                var x = tileoffsetx;
                x -= layerContainerDivLeft;

                var y = tileoffsety;
                y -= layerContainerDivTop;

                var px = new OpenLayers.Pixel(x, y);
                var tile = row[colidx++];
                if (!tile) {
                    tile = this.addTile(tileBounds, px);
                    this.addTileMonitoringHooks(tile);
                    row.push(tile);
                } else {
                    tile.moveTo(tileBounds, px, false);
                }
     
                tileoffsetlon += tilelon;       
                tileoffsetx += this.tileSize.w;
            } while ((tileoffsetlon <= bounds.right + tilelon * this.buffer)
                     || colidx < minCols);
             
            tileoffsetlat -= tilelat;
            tileoffsety += this.tileSize.h;
        } while((tileoffsetlat >= bounds.bottom - tilelat * this.buffer)
                || rowidx < minRows);
        
        //shave off exceess rows and colums
        
        this.removeExcessTiles(rowidx, colidx);
        
        //now actually draw the tiles
        this.spiralTileLoad();
    },
    CLASS_NAME: "OpenLayers.Layer.TileCacheCustom"
});
        
        
OpenLayers.Util.onImageLoadError = function() {
    this._attempts = (this._attempts) ? (this._attempts + 1) : 1;
    if (this._attempts <= OpenLayers.IMAGE_RELOAD_ATTEMPTS) {
        var urls = this.urls;
        if (urls && urls instanceof Array && urls.length > 1){
            var src = this.src.toString();
            var current_url, k;
            for (k = 0; current_url = urls[k]; k++){
                if(src.indexOf(current_url) != -1){
                    break;
                }
            }
            var guess = Math.floor(urls.length * Math.random());
            var new_url = urls[guess];
            k = 0;
            while(new_url == current_url && k++ < 4){
                guess = Math.floor(urls.length * Math.random());
                new_url = urls[guess];
            }
            this.src = src.replace(current_url, new_url);
        } else {
            this.src = this.src;
        }
    } else {
        this.style.backgroundColor = OpenLayers.Util.onImageLoadErrorColor;
        this.src = "img/blank.png";        
    }
    this.style.display = "";
};       
///编辑栏扩展
OpenLayers.Control.EditingToolbar.prototype.activateControl = OpenLayers.Control.Panel.prototype.activateControl;
OpenLayers.Control.EditingToolbar.prototype.initialize= function(layer, options) {
        OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]);        
        var vlayer = layer;
        var controls = [
          new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point, {title:'增加点覆盖','displayClass': 'olControlDrawFeaturePoint'}),
          new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, {title:'增加线覆盖','displayClass': 'olControlDrawFeaturePath'}),
          new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, {title:'增加面覆盖','displayClass': 'olControlDrawFeaturePolygon'}),
          new OpenLayers.Control.SelectFeature(layer,{title:'删除覆盖',onSelect:function(feature){if(!feature.data.featureid){layer.removeFeatures([feature]);return;}feature.data.action='delete';feature.style=GeoStyle.del;}}),
          new OpenLayers.Control.DragFeature(layer,{title:'移动覆盖',onComplete:function(feature,pixel){if(feature.data.featureid) {feature.style=GeoStyle.update;feature.data.action = 'modify';vlayer.drawFeature(feature);}}}),
          new OpenLayers.Control.ModifyFeature(layer,{title:'修改覆盖',deleteCodes:[46]}),
          new OpenLayers.Control.Button({title:'保存覆盖规划',displayClass: "olControlSaveFeatures", trigger: saveCoverage})

        ];
        this.addControls(controls);
    };    
OpenLayers.Control.EditingToolbar.prototype.draw = function() {
        var div = OpenLayers.Control.Panel.prototype.draw.apply(this, arguments);
        return div;
    };
OpenLayers.Feature.prototype.createMarker = function(){
    if (this.lonlat != null) {
        this.marker = new OpenLayers.Marker(this.lonlat, this.data.icon);
        this.marker.feature = this;
    }    
    return this.marker;
};
OpenLayers.Layer.Text.prototype.parseData = function(ajaxRequest) {
        var text = ajaxRequest.responseText;
        var options = {};
        
        OpenLayers.Util.extend(options, this.formatOptions);
        
        if (this.map && !this.projection.equals(this.map.getProjectionObject())) {
            options.externalProjection = this.projection;
            options.internalProjection = this.map.getProjectionObject();
        }    
        
        var parser = new OpenLayers.Format.Text(options);
        var features = parser.read(text);
        for (var i=0, len=features.length; i<len; i++) {
            var data = {};
            var feature = features[i];
            var location;
            var iconSize, iconOffset;
            
            location = new OpenLayers.LonLat(feature.geometry.x, 
                                             feature.geometry.y);
            
            if (feature.style.graphicWidth 
                && feature.style.graphicHeight) {
                iconSize = new OpenLayers.Size(
                    feature.style.graphicWidth,
                    feature.style.graphicHeight);
            }        
            
            // FIXME: At the moment, we only use this if we have an 
            // externalGraphic, because icon has no setOffset API Method.
            /**
             * FIXME FIRST!!
             * The Text format does all sorts of parseFloating
             * The result of a parseFloat for a bogus string is NaN.  That
             * means the three possible values here are undefined, NaN, or a
             * number.  The previous check was an identity check for null.  This
             * means it was failing for all undefined or NaN.  A slightly better
             * check is for undefined.  An even better check is to see if the
             * value is a number (see #1441).
             */
            if (feature.style.graphicXOffset !== undefined
                && feature.style.graphicYOffset !== undefined) {
                iconOffset = new OpenLayers.Pixel(
                    feature.style.graphicXOffset, 
                    feature.style.graphicYOffset);
            }
            
            if (feature.style.externalGraphic != null) {
                data.icon = new OpenLayers.Icon(feature.style.externalGraphic, 
                                                iconSize, 
                                                iconOffset);
            } else {
                data.icon = OpenLayers.Marker.defaultIcon();

                //allows for the case where the image url is not 
                // specified but the size is. use a default icon
                // but change the size
                if (iconSize != null) {
                    data.icon.setSize(iconSize);
                }
            }
            
            if ((feature.attributes.title != null) 
                && (feature.attributes.description != null)) {
                data['popupContentHTML'] = 
                    '<h2>'+feature.attributes.title+'</h2>' + 
                    '<p>'+feature.attributes.description+'</p>';
            }
            
            data['overflow'] = feature.attributes.overflow || "auto"; 
            var markerFeature = new OpenLayers.Feature(this, location, feature.attributes);
            markerFeature.data['overflow'] = data['overflow'];
            markerFeature.data['popupContentHTML'] = data['popupContentHTML'];
            markerFeature.data.icon = data.icon;
            markerFeature.closeBox = true;
            markerFeature.popupClass = AutoSizeFramedCloud;
            this.features.push(markerFeature);
            var markerClick = function (evt) {
            	for(var i=0, len=this.layer.map.popups.length; i<len; i++) {
	            this.layer.map.removePopup(this.layer.map.popups[i]);
	        };
                if (true || this.popup == null) {
                    this.popup = this.createPopup(this.closeBox);
                    map.addPopup(this.popup);
                    this.popup.show();
                } else {
                    this.popup.toggle();
                }
                currentPopup = this.popup;
                OpenLayers.Event.stop(evt);
            };
            var marker = markerFeature.createMarker();
            marker.label = feature.attributes.label;
            if ((feature.attributes.title != null) 
                && (feature.attributes.description != null)) {
              marker.events.register('click', markerFeature, markerClick);
            }
            this.addMarker(marker);
        }
        this.events.triggerEvent("loadend");
    };           
    OpenLayers.Control.DrawFeature.prototype.activate = function () {
        if (this.active) {
            return false;
        }
        if (this.handler) {
            this.handler.activate();
        }
        this.active = true;
        if(this.map) {
            OpenLayers.Element.addClass(
                this.map.viewPortDiv,
                this.displayClass.replace(/ /g, "") + "Active"
            );
        }
        var control = this;
        if(control.map) {
            for(var i = 0; i < control.map.controls.length; i++){
                var control2 = control.map.controls[i];
                if(control2.controls){                
                    for(var j = 0; j < control2.controls.length;j++){
                        var control1 = control2.controls[j];
                        if(control1 != control)
                            control1.deactivate();
                    }
                }
                else {
                    if(control2 != control)
                         control2.deactivate();
                }
            }
        }                  
        this.events.triggerEvent("activate");
        return true;
    };
    OpenLayers.Popup.COLOR = "#CEDFF5";